﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public class SendDocDAO : BaseService
    {
        /// <summary>
        /// 查询发送资料历史数量
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public int  GetListPaging(int userid)
        {
            string hql = "select cpunt(*) from SendDoc where 1=1 and IsDel=false and IsPub = false and UserId="+userid;
            try
            {
                return Convert.ToInt32(GetValue(hql));
            }
            catch (Exception)
            {

                return 0;
            }
        }
        /// <summary>
        /// 查询发送资料历史
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IList<SendDoc> GetListPaging(int page, int pagesize, int userid)
        {
            string hql = "from SendDoc where 1=1 and IsDel=false and IsPub = false and UserId=" + userid;
            return FindList<SendDoc>(hql, null, (page - 1) * pagesize, pagesize);
        }
        /// <summary>
        /// 根据发布信息用户和状态查询任务信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <param name="userid"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public IList<SendDoc> GetListPaging(int page, int pagesize, int userid, string state, bool isDel)
        {
            string hql = "from SendDoc where 1=1 and IsDel=false and IsPub = false";
            if (state == "-99")
            {
                hql += " and IsUser = " + userid;
            }
            else
            {
                hql += " and IsUser = " + userid + " and State in ('" + state + "')";
            }
            hql += " and IsDel=" + isDel + " order By AddDate Desc";
            return FindList<SendDoc>(hql, null, (page - 1) * pagesize, pagesize);
        }
        /// <summary>
        /// 根据发布信息用户和状态查询任务信息条目数
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public int GetListPaging(int userid, string state, bool isDel)
        {
            string hql = "select count(*) from SendDoc where 1=1 and IsDel=false and IsPub = false";
            if (state == "-99")
            {
                hql += " and IsUser = " + userid;
            }
            else
            {
                hql += " and IsUser = " + userid + " and State in ('" + state + "')";
            }
            hql += " and IsDel=" + isDel;
            return Convert.ToInt32(GetValue(hql));
        }
        /// <summary>
        /// 根据处理意见用户和状态查询任务信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <param name="worker"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public IList<SendDoc> GetListPagingByWorker(int page, int pagesize, int worker, string state)
        {
            string hql = "from SendDoc where 1=1";
            if (state == "-99")
            {
                hql += " and Worker =" + worker;
            }
            else
            {
                hql += " and Worker =" + worker + " and State in (" + state + ")";
            }
            hql += " and IsDel=false and IsPub = false order By AddDate Desc";
            return FindList<SendDoc>(hql, null, (page - 1) * pagesize, pagesize);
        }
        /// <summary>
        /// 根据处理意见用户和状态查询任务信息条目数
        /// </summary>
        /// <param name="worker"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public int GetListPagingByWorker(int worker, string state)
        {
            string hql = "select count(*) from SendDoc where 1=1";
            if (state == "-99")
            {
                hql += " and Worker =" + worker;
            }
            else
            {
                hql += " and Worker =" + worker + " and State in (" + state + ")";
            }
            hql += " and IsDel=false and IsPub = false ";
            return Convert.ToInt32(GetValue(hql));
        }


        /// <summary>
        /// 查询待分发资料
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="isPub"></param>
        /// <param name="isDel"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IList<SendDoc> GetListPagings( int userid, bool isPub, bool isDel, int page, int pagesize)
        {
            string hql = "from SendDoc where 1=1 and  UserId=" + userid + " and IsPub=" + isPub + " and IsDel = " + isDel + " order by AddDate desc";
            try
            {
                return FindList<SendDoc>(hql, null, (page - 1) * pagesize, pagesize);
            }
            catch (Exception)
            {
                return null;

            }
        }


        /// <summary>
        /// 查询待分发资料数量
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="isPub"></param>
        /// <param name="isDel"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public int GetListPagings( int userid, bool isPub, bool isDel)
        {
            string hql = "select count(*) from SendDoc where 1=1 and  UserId=" + userid + " and IsPub=" + isPub + " and IsDel = " + isDel;
            try
            {
                return Convert.ToInt32(GetValue(hql));
            }
            catch (Exception)
            {

                return 0;
            }
        }


        /// <summary>
        /// 查询已删除资料
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="isPub"></param>
        /// <param name="isDel"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IList<SendDoc> GetListPagings(int userid,  bool isDel, int page, int pagesize)
        {
            string hql = "from SendDoc where 1=1 and  UserId=" + userid + "  and IsDel = " + isDel + " order by AddDate desc";
            try
            {
                return FindList<SendDoc>(hql, null, (page - 1) * pagesize, pagesize);
            }
            catch (Exception)
            {
                return null;

            }
        }


        /// <summary>
        /// 查询已删除资料数量
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="isPub"></param>
        /// <param name="isDel"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public int GetListPagings(int userid,  bool isDel)
        {
            string hql = "select count(*) from SendDoc where 1=1 and  UserId=" + userid + "  and IsDel = " + isDel;
            try
            {
                return Convert.ToInt32(GetValue(hql));
            }
            catch (Exception)
            {

                return 0;
            }
        }


        /// <summary>
        /// 批量修改暂存
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>

        public Boolean BatchSendDocUpdate(string ids)
        {
            string hql = "update SendDoc set IsPub = false where Id in (" + ids + ")";
            try
            {
                DBHelper.TransDeleteByHQL(hql);
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }

        /// <summary>
        /// 批量修改删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>

        public Boolean BatchSendDocDelete(string ids)
        {
            string hql = "update SendDoc set IsDel = true where Id in (" + ids + ")";
            try
            {
                DBHelper.TransDeleteByHQL(hql);
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }


        /// <summary>
        /// 批量修改暂存
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>

        public Boolean BatchSSendDocUpdate(string ids)
        {
            string hql = "update SendDoc set IsDel = false where Id in (" + ids + ")";
            try
            {
                DBHelper.TransDeleteByHQL(hql);
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }

        /// <summary>
        /// 批量修改删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>

        public Boolean BatchSSendDocDelete(string ids)
        {
            string hql = "delete SendDoc where Id in (" + ids + ")";
            try
            {
                DBHelper.TransDeleteByHQL(hql);
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
    }
}
